home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TDE10SRC.ARJ
/
HWIND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-05
|
12KB
|
383 lines
/******************* start of original comments ********************/
/*
* Written by Douglas Thomson (1989/1990)
*
* This source code is released into the public domain.
*/
/*
* Name: hardware independent screen IO module
* Purpose: This file contains the code to interface the rest of the
* editor to the display and input hardware.
* File: hwind.c
* Author: Douglas Thomson
* System: this file is intended to be system-independent
* Date: October 2, 1989
* Notes: This is the only module that is allowed to call the hardware
* dependent display IO library.
* Typically, functions here check whether any action is
* necessary (for example, the cursor may already happen to be
* in the required position), call hardware dependent functions
* to achieve the required effect, and finally update status
* information about the current state of the terminal display.
* The idea behind this approach is to keep the hardware
* dependent code as small and simple as possible, thus making
* porting the code easier.
*/
/********************* end of original comments ********************/
/*
* Some routines were added to display current editor modes in the lite bar
* at the bottom of the screen. Other routines were rewritten in assembly.
* I feel the need for speed.
*
* New editor name: tde, the Thomson-Davis Editor.
* Author: Frank Davis
* Date: June 5, 1991
*
* This modification of Douglas Thomson's code is released into the
* public domain, Frank Davis. You may distribute it freely.
*/
#include "tdestr.h"
#include "common.h"
#include "tdefunc.h"
/*
* Name: xygoto
* Purpose: To move the cursor to the required column and line.
* Date: October 2, 1989
* Passed: col: desired column (0 up to max)
* line: desired line (0 up to max)
* Notes: This function makes some attempt to use shorter movement
* commands for simple movements (initially, only backspace
* to move left one space).
*/
void xygoto( col, line )
int col;
int line;
{
g_display.col = col;
g_display.line = line;
hw_xygoto( );
}
/*
* Name: save_screen_line
* Purpose: To save the characters and attributes of a line on screen.
* Date: June 5, 1991
* Notes: No need to redraw entire screen to show a prompt. Just save
* the contents of the line on screen where prompt is to be displayed
*/
void save_screen_line( int col, int line, char *screen_buffer )
{
char far *p;
p = g_display.display_address + line * 160 + col * 2;
memcpy( screen_buffer, p, 160 );
}
/*
* Name: restore_screen_line
* Purpose: To restore the characters and attributes of a line on screen.
* Date: June 5, 1991
* Notes: No need to redraw entire screen to show a prompt. Just save
* the contents of the line on screen where prompt is to be displayed
*/
void restore_screen_line( int col, int line, char *screen_buffer )
{
char far *p;
p = g_display.display_address + line * 160 + col * 2;
memcpy( p, screen_buffer, 160 );
}
/*
* Name: force_blank
* Purpose: To set the status of the screen so that nothing can appear to
* be what it needs to be, so that the entire screen will be
* redrawn.
* Date: June 5, 1991
* Notes: Call the video BIOS routine to clear the screen.
*/
void force_blank( )
{
int line;
line = g_display.nlines+1;
_asm {
xor ch, ch ; starting row in ch = 0
xor cl, cl ; starting column in cl = 0
mov ax, WORD PTR line ; get ending row
mov dh, al ; put it in dh
mov dl, 79 ; ending column in dl = 79
mov bh, 7 ; attribute in bh = 7 (normal)
mov al, 0 ; get number of lines
mov ah, 6 ; get function number
push bp ; some dos versions wipeout bp
int 0x10
pop bp
}
}
/*
* Name: initialize
* Purpose: To initialize all the screen status info that is not hardware
* dependent, and call the hardware initialization routine to
* pick up the hardware dependent stuff.
* Date: June 5, 1991
* Returns: [g_status and g_display]: all set up ready to go
* Notes: It is assumed that g_status and g_display are all \0's to begin
* with (the default if they use static storage). If this may
* not be the case, then clear them explicitly here.
*/
void initialize( )
{
/*
* we do not know where the cursor is yet
*/
g_display.col = -1;
g_display.line = -1;
/*
* do the hardware initialization first, since this allocates the main
* text buffer and sets up other info needed here later.
*/
hw_initialize( );
bm.search_defined = ERROR;
bm.search_case = IGNORE;
/*
* the main text buffer must be preceded by a ^Z, so that backward
* searches can see the start of the text buffer
*/
*g_status.start_mem++ = CONTROL_Z;
/*
* most of the system's text pointers are safer set to the start
* of the text buffer - some of these may not be strictly
* necessary.
*/
g_status.temp_end = g_status.start_mem;
g_status.end_mem = g_status.start_mem;
/*
* set the default modes - may want to read this from a file later
*/
g_status.insert = TRUE;
g_status.indent = TRUE;
g_status.marked = FALSE;
g_status.marked_file = NULL;
g_status.current_window = NULL;
g_status.current_file = NULL;
g_status.window_list = NULL;
g_status.file_list = NULL;
g_status.file_count = 0;
/*
* set default interval between tabs
*/
g_status.tab_size = 8;
/*
* set the number of lines from one page that should still be visible
* on the next page after page up or page down.
*/
g_status.overlap = 1;
/*
* clear the screen and show the author's names
*/
force_blank( );
show_credits( );
}
/*
* Name: show_modes
* Purpose: show current editor modes in lite bar at bottom of screen
* Date: June 5, 1991
*/
void show_modes( )
{
char status_line[MAX_COLS+2];
char *p;
memset( status_line, ' ', MAX_COLS );
status_line[MAX_COLS] = '\0';
status_line[78] = (g_status.insert == TRUE) ? 'i' : 'o';
s_output( status_line, g_display.mode_line, 0, g_display.mode_color );
s_output( "Files = ", g_display.mode_line, 1, g_display.mode_color );
s_output( "memory = ", g_display.mode_line, 13, g_display.mode_color );
show_file_count( g_status.file_count );
show_avail_mem( );
show_indent_mode( );
show_search_case( );
}
/*
* Name: show_file_count
* Purpose: show number of open files in lite bar at bottom of screen
* Date: June 5, 1991
*/
void show_file_count( fc )
int fc;
{
char status_line[MAX_COLS+2];
int mode_line, mode_color;
mode_line = g_display.mode_line;
mode_color = g_display.mode_color;
s_output( " ", mode_line, 9, mode_color );
s_output( itoa( fc, status_line, 10 ), mode_line, 9, mode_color );
}
/*
* Name: show_avail_mem
* Purpose: show available free memory in lite bar at bottom of screen
* Date: June 5, 1991
*/
void show_avail_mem( )
{
char memory[MAX_COLS+2];
int mode_line, mode_color;
unsigned long avail;
avail = ptoul( g_status.max_mem ) - ptoul( g_status.end_mem );
ultoa( avail, memory, 10 );
mode_line = g_display.mode_line;
mode_color = g_display.mode_color;
s_output( " ", mode_line, 22, mode_color );
s_output( memory, mode_line, 22, mode_color );
}
/*
* Name: show_indent_mode
* Purpose: show indent mode in lite bar at bottom of screen
* Date: June 5, 1991
*/
void show_indent_mode( )
{
int mode_line, mode_color;
mode_line = g_display.mode_line;
mode_color = g_display.mode_color;
if (g_status.indent)
s_output( "Indent", mode_line, 32, mode_color );
else
s_output( " ", mode_line, 32, mode_color );
}
/*
* Name: show_search_case
* Purpose: indicate whether to ignore or match case on search strings
* Date: June 5, 1991
*/
void show_search_case( )
{
int mode_line, mode_color;
mode_line = g_display.mode_line;
mode_color = g_display.mode_color;
if (bm.search_case == IGNORE)
s_output( "Ignore", mode_line, 42, mode_color );
else
s_output( "Match ", mode_line, 42, mode_color );
}
/*
* Name: terminate
* Purpose: To do any hardware independent housekeeping, and call the
* hardware dependent code to clean up screen modes and leave
* the cursor at the bottom of the screen in normal attribute.
* Date: October 2, 1989
* Notes: At present, there is nothing apart from hardware dependent
* code required.
*/
void terminate( )
{
hw_terminate( );
}
/*
* Name: window_scroll_up
* Purpose: To scroll all the lines between top and bottom up one line.
* Date: June 5, 1991
* Passed: top: top line to be scrolled
* bottom: bottom line to be scrolled
* Notes: Call the video BIOS routine to scroll window up.
*/
void window_scroll_up( top, bottom )
int top;
int bottom;
{
_asm {
mov ax, WORD PTR top ; get starting row
mov ch, al ; put it in ch
xor cl, cl ; startin column in cl = 0
mov ax, WORD PTR bottom ; get ending row
mov dh, al ; put it in dh
mov dl, 79 ; ending column in dl = 79
mov bh, 7 ; attribute in bh = 7 (normal)
mov al, 1 ; get number of lines
mov ah, 6 ; get function number
push bp
int 0x10
pop bp
}
}
/*
* Name: window_scroll_down
* Purpose: To scroll all the lines between top and bottom down one line.
* Date: June 5, 1991
* Passed: top: top line to be scrolled
* bottom: bottom line to be scrolled
* Notes: Call the video BIOS routine to scroll window down.
*/
void window_scroll_down( top, bottom )
int top;
int bottom;
{
_asm {
mov ax, WORD PTR top ; get starting row
mov ch, al ; put it in ch
xor cl, cl ; put starting column in cl - 0
mov ax, WORD PTR bottom ; get ending row
mov dh, al ; put it in dh
mov dl, 79 ; put ending column in dl
mov bh, 7 ; put attribute in bh
mov ah, 7 ; get function number
mov al, 1 ; get number of lines
push bp
int 0x10
pop bp
}
}
/*
* Name: combine_strings
* Purpose: stick 3 strings together
* Date: June 5, 1991
* Passed: buff: buffer to hold concatenation of 3 strings
* s1: pointer to string 1
* s2: pointer to string 2
* s3: pointer to string 3
*/
void combine_strings( char *buff, char *s1, char *s2, char *s3 )
{
strcpy( buff, s1 );
strcat( buff, s2 );
strcat( buff, s3 );
}